<!--
 * @Author: linZeJian
 * @Date: 2022-11-01 14:05:05
 * @LastEditors: linZeJian
 * @LastEditTime: 2022-11-02 10:23:11
 * @Description: 
-->
<!--
 * @Author: linZeJian
 * @Date: 2022-08-24 10:53:55
 * @LastEditors: linZeJian
 * @LastEditTime: 2022-11-01 14:06:08
 * @Description: 
-->
<template>
  <div v-if="option.display">
    <uni-forms-item
      :label="option.label"
      :required="option.required"
      :rules="[{ required: option.required, errorMessage: '必填项不能为空' }]"
      :name="option.prop"
    >
      <uni-easyinput
        v-model="comValue"
        :placeholder="
          option.placeholder ? option.placeholder : '请输入' + option.label
        "
        :style="detailValue ? 'pointer-events: none;' : ''"
        :clearable="false"
        :disabled="true"
      />
    </uni-forms-item>
  </div>
</template>

<script>
// import { uid } from "uid";
// import moment from "moment";
// js重写方法
import { uid } from "../utils/uuidjs";
import {formatDate} from "../utils/methods";
export default {
  name: "auni-info-custom",
  props: {
    option: Object,
    value: [String, Number],
  },
  data() {
    return {};
  },
  computed: {
    comValue: {
      get() {
        // console.log("this.option :>> ", this.option);
        return this.value;
      },
      set(val) {
        // 触发value绑定值的交互与更新
        this.$emit("input", val);
      },
    },
    // 处理详情模式
    detailValue() {
      if (this.option.detail) {
        return true;
      } else {
        return false;
      }
    },
  },
  created() {},
  watch: {
    value: {
      deep: true,
      immediate: true,
      handler(newV) {},
    },
  },
  async mounted() {
    // 非详情模式不请求,发起模式才请求
    if (!this.option.detail) {
      let infoData = {};
      let info = "";
      if (this.option.params.type == "userInfo") {
        let res = await this.$request.getLoginUserInfo();
        infoData = res.data;
        info = infoData[this.option.params.key];
      } else if (this.option.params.type == "uid") {
        info = uid(32);
      } else if (this.option.params.type == "timestamp") {
        info = new Date().getTime();
      } else if (this.option.params.type == "time") {
        info = formatDate(new Date().getTime());
      }
      this.comValue = info;
      // console.log("this.info :>> ", info, infoData);
    }
  },
  methods: {},
};
</script>

<style></style>
